package com.borya.util.mq;

import com.borya.util.Constant;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 描述:
 * mq
 *
 * @Author: CYH
 * @Date: 2020/2/13 16:00
 */
public class RabbitFactory {

    private static final String HOST = Constant.RABBIT_HOST;
    private static final Integer PORT = Constant.RABBIT_PORT;
    private static final String USER_NAME = Constant.RABBIT_USERNAME;
    private static final String PASSWORD = Constant.RABBIT_PASSWORD;

    public static Connection getConnection() throws Exception {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost(HOST);
        //端口
        factory.setPort(PORT);
        //设置账号信息，用户名、密码、vhost
//        factory.setVirtualHost("testhost");
        factory.setUsername(USER_NAME);
        factory.setPassword(PASSWORD);
        // 通过工程获取连接
        Connection connection = factory.newConnection();
        return connection;
    }
}
